package com.apes.scm.masterdata.finance.service;

import com.alibaba.fastjson.JSON;
import com.apes.framework.api.DomainService;
import com.apes.framework.jpa.spec.JpaDsl;
import com.apes.framework.plugin.esb.api.SimpleRequest;
import com.apes.scm.account.tax.model.Tax;
import com.apes.scm.masterdata.finance.model.IncomeType;
import com.apes.scm.masterdata.finance.repository.IncomeTypeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author yiny
 */
@Service("incomeTypeService")
public class IncomeTypeService extends DomainService{

    @Autowired
    private IncomeTypeRepository incomeTypeRepository;


    public IncomeType save(SimpleRequest request){
        IncomeType incomeType = request.getO(IncomeType.class);
        return incomeTypeRepository.saveAndFlush(incomeType);
    }
    public IncomeType update(SimpleRequest request) {
        IncomeType incomeType = request.getO(IncomeType.class);
        incomeType.setUpdateDate(new Date());
        return incomeTypeRepository.saveAndFlush(incomeType);
    }

    public Page<IncomeType> findAll(SimpleRequest request) {
        List<Map> list = request.get("condition");
        return incomeTypeRepository.findAll(JpaDsl.toCriteria(list), PageRequest.of(request.get("page"), request.get("size")));
    }
}
